package cron

import "time"

// NewCron 对外新建一个定时任务，f是执行闭包，inter是f的入参
func NewCron(tConfig TimeConfig, ctx *Context, f ...DoCronFunc) *JobCron {
	j := new(JobCron)
	j.tConfig = tConfig
	j.Task = f
	j.ctx = ctx
	return j
}

func (j *JobCron) Start() {
	j.tConfig.BeginAt = time.Now()
	for _, timePass := range j.tConfig.Interval {
		ticker := time.NewTicker(timePass)
		go func() {
			for {
				select {
				case <-ticker.C:
					for _, task := range j.Task {
						task(j.ctx)
					}
				}
			}
		}()
	}
	for {

	}
}

// sortTime 对定时执行返回一个chan
//func (j *JobCron) cronTime() <-chan time.Time {
//	j.tConfig.Cron.
//}
